從上一章節中,我們知道了使用內含預先編譯好的ClickHouse資料庫壓縮檔與ClickHouse資料庫的Docker映像檔來進行安裝,在本章節中,我們會展示如何使用單一個二進位編譯好的執行檔與給非標準的環境使用預先編譯好的二進位執行檔來安裝ClickHouse資料庫。
我們可以使用curl
指令從https://builds.clickhouse.com/master/amd64/clickhouse
網址進行下載已經編譯好的二進位執行檔,這個單一且可攜式的預先編譯好的二進位執行檔是從ClickHouse專案的master
分支進行編譯而來的,相關的安裝指令如下所示:
curl -O 'https://builds.clickhouse.com/master/amd64/clickhouse' && chmod a+x clickhouse
sudo ./clickhouse install
我們以Ubuntu 18.04的Linux發行版本的作業系統執行上述的指令,得到執行指令期間相關的輸出訊息如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ curl -O 'https://builds.clickhouse.com/master/amd64/clickhouse' && chmod a+x clickhouse
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 450M 100 450M 0 0 11.3M 0 0:00:39 0:00:39 --:--:-- 13.4M
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo ./clickhouse install
[sudo] password for peter:
Copying ClickHouse binary to /usr/bin/clickhouse.new
Renaming /usr/bin/clickhouse.new to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
groupadd -r clickhouse
Creating clickhouse user if it does not exist.
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Data path configuration override is saved to file /etc/clickhouse-server/config.d/data-paths.xml.
Log path configuration override is saved to file /etc/clickhouse-server/config.d/logger.xml.
User directory path configuration override is saved to file /etc/clickhouse-server/config.d/user-directories.xml.
OpenSSL path configuration override is saved to file /etc/clickhouse-server/config.d/openssl.xml.
Creating log directory /var/log/clickhouse-server.
Creating data directory /var/lib/clickhouse.
Creating pid directory /var/run/clickhouse-server.
chown -R clickhouse:clickhouse '/var/log/clickhouse-server'
chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
chown clickhouse:clickhouse '/var/lib/clickhouse'
Enter password for default user:
Allow server to accept connections from the network (default is localhost only), [y/N]: N
chown -R clickhouse:clickhouse '/etc/clickhouse-server'
ClickHouse has been successfully installed.
Start clickhouse-server with:
sudo clickhouse start
Start clickhouse-client with:
clickhouse-client --password
從上面指令可以得知,除了會問default預設使用者要使用者輸入設定的密碼之外,還會詢問是否要允許ClickHouse資料庫伺服器可以允許外部的連線,選擇「N」的話,則是只有本地端才可以連到ClickHouse資料庫,若選擇「y」則是可以讓外部的客戶端也可以連線到此ClickHouse資料庫,這些設定在資料庫的設定檔中仍可以做修改,修改設定的方式,在後面的章節會提到。
透過上述的指令安裝好資料庫之後,接著可以使用sudo clickhouse start
來啟動資料庫伺服器了,相關的執行指令與輸出的結果如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo clickhouse start
[sudo] password for peter:
chown -R clickhouse: '/var/run/clickhouse-server/'
Will run clickhouse su 'clickhouse' /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
Waiting for server to start
Waiting for server to start
Server started
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
透過上述指令啟動完成之後,接著可以使用clickhouse-client
來確認是否ClickHouse資料庫伺服器有順利的啟動成功,相關的執行指令與輸出的結果如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ clickhouse-client --password
ClickHouse client version 22.9.1.1478 (official build).
Password for user (default):
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.9.1 revision 54460.
Warnings:
* Linux is not using a fast TSC clock source. Performance can be degraded. Check /sys/devices/system/clocksource/clocksource0/current_clocksource
ubuntu-s-4vcpu-8gb-amd-sgp1-01 :)
因為先前安裝的時候有設定密碼,因此在使用clickhouse-client
指令則是要再加上--password
的參數來讓clickhouse-client
知道要讓使用者輸入密碼。
要離開ClickHouse客戶端,則跟之前的章節有提到的,輸入exit
或是使用「ctrl」加上「d」組合鍵即可。
對於非Linux為基礎的發行版的作業系統以及基於ARM64位元(AArch64)的CPU架構的機器ClickHouse也預先從原始碼專案上的master
分支來建置並透過跨編譯的方式來編譯出目標的二進位位元執行檔,編譯出這類的二進位位元檔並非即時的,可能會有幾個小時的延遲,造成已經編譯好的版本與在master
分支上的原始碼有著差異性,下列列出幾種目前ClickHouse官方有支援的非標準的環境:
curl -O 'https://builds.clickhouse.com/master/macos/clickhouse' && chmod a+x ./clickhouse
curl -O 'https://builds.clickhouse.com/master/macos-aarch64/clickhouse' && chmod a+x ./clickhouse
curl -O 'https://builds.clickhouse.com/master/freebsd/clickhouse' && chmod a+x ./clickhouse
curl -O 'https://builds.clickhouse.com/master/aarch64/clickhouse' && chmod a+x ./clickhouse
下載完成之後,接著可以使用下列的指令進行ClickHouse資料庫的安裝並會安裝到當前的作業系統環境中:
sudo ./clickhouse install
在上述安裝的過程中,同時會有default使用者密碼設定與資料庫存取連線等設定,在安裝完成之後,接著可以執行下列的指令將安裝好的ClickHouse資料啟動起來,相關的執行指令如下:
sudo clickhouse start
在成功啟動ClickHouse資料庫之後,接著可以使用下列其中一的指令來連線到上述啟動好的ClickHouse資料庫:
clickhouse-client --password
clickhouse client --password
clickhouse local
因為在先前設定ClickHouse資料庫的時候,有設定預設使用者default的密碼,因此使用clickhouse-client
與clickhouse client
等指令進行資料庫連線的時候,都需要加入--password
的參數,讓ClickHouse客戶端可以跳出使用者密碼輸入的訊息讓使用者可以輸入設定的密碼,連上去之後,後續的操作方法都與先前介紹的相同,可以參考先前的安裝方法裡面所提到的ClickHouse客戶端操作的步驟與方法。
在本章節中,我們展示了使用單一二進位位元執行檔與載非標準環境的預先編譯的二進位位元執行檔進行ClickHouse資料庫安裝,在下一章節中,將會介紹如何從ClickHouse專案的原始碼來進行編譯與安裝ClickHouse資料庫。